/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package config;
//configura os parametros do sistema


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import model.persistence.PostgresTransactionManager;
import model.persistence.TransactionManager;

/**
 *
 * @author JUSCELINO
 */
public class ApplicationConfig {
// o objeto dessa classe as configurações

    private Properties configProperties;
    private static ApplicationConfig instance = null;

    private ApplicationConfig() throws FileNotFoundException, IOException {
        this.configProperties = new Properties();

    }

    private void loadFile() throws FileNotFoundException, IOException {
        this.configProperties.load(new FileInputStream("config/app.properties"));

    }

    public static ApplicationConfig getInstance() throws FileNotFoundException, IOException {
        if (instance == null) {
            instance = new ApplicationConfig();

        }
        instance.loadFile();
        return instance;
    }

    public TransactionManager getTransactionManager() {
        String username = this.configProperties.getProperty("username");
        String password = this.configProperties.getProperty("password");
        String database = this.configProperties.getProperty("database");
        String hostname = this.configProperties.getProperty("hostname");
        String port = this.configProperties.getProperty("port");
        //        System.out.println(username);

        TransactionManager manager = new PostgresTransactionManager(username, password, database);
        return manager;

    }
}
